package cn.yunhe.controller;

import cn.yunhe.entity.Lib;
import cn.yunhe.services.ILibServices;
import com.github.pagehelper.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by 王雪丹 on 2018/5/23.
 */
@RestController
@RequestMapping("/lib")
public class LibController {
    @Resource
    private ILibServices libServices;

    @RequestMapping("/getPage")
    public Map queryUserByPage(int pageSize, int pageNum, Lib lib){
        Map map = new HashMap<>();
        map.put("pageSize",pageSize);
        map.put("pageNum",pageNum);
        map.put("lib",lib);
        Page page = libServices.queryListLikeLib(map);
        map.put("page",page);
        map.put("totalPage",page.getPages());
        return map;
    }

    @RequestMapping("/addLib")
    public int addLib(Lib lib){
        return libServices.addLib(lib);
    }
    @RequestMapping("/toAddLib")
    public ModelAndView toAddLib(){
        return new ModelAndView("ftl/addLib");
    }

    @RequestMapping("/toUpadteLib")
    public ModelAndView toUpadteLib(Lib lib){
        lib = libServices.getOne(lib);
        ModelAndView mv = new ModelAndView();
        mv.addObject("lib",lib);
        mv.setViewName("ftl/toUpadteLib");
        return mv;
    }

    @RequestMapping("/delLib")
    public int delLib(Lib lib){
        return libServices.delLib(lib);
    }

    public ILibServices getLibServices() {
        return libServices;
    }

    public void setLibServices(ILibServices libServices) {
        this.libServices = libServices;
    }
}
